package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author MrZhao
 * @created 2025-10-08 18:28
 * @description 角色管理Controller
 *
 */
@Slf4j
@RestController
@RequestMapping(path = "/roles")
@SuppressWarnings("all")
public class RoleController {


    @Autowired
    private RoleService roleService;

    @PutMapping
    public Result update(@RequestBody RoleDTO dto){
        log.info("修改角色：{}", dto);
        roleService.updateById(dto);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(roleService.getById(id));
    }

    @PostMapping
    public Result add(@RequestBody RoleDTO dto){
        roleService.add(dto);
        return Result.success();
    }

    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable Integer id){
        roleService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result page(RoleDTO dto){
       PageResult<Role> result = roleService.page(dto);
        return Result.success(result);
    }
    @GetMapping("/list")
    public Result list(){
        return Result.success(roleService.list());
    }

}
